﻿namespace Devonline.Entity;

/// <summary>
/// 订单明细
/// </summary>
[DisplayName("订单明细")]
public class OrderDetailViewModel : OrderDetailViewModel<string>, IViewModel, IEntitySet
{
    /// <summary>
    /// 单品总体积, 单位 m³
    /// TOTAL VOLUME 单品总体积, 尺寸单位 m³, 体积在 cm³ 级别取整数
    /// 公式: Volume => ProductPackage is null ? 0 : ProductPackage.Volume * Cartons;
    /// </summary>
    [DisplayName("体积"), Excel]
    public virtual decimal? Volume => ProductPackage is null ? 0 : ProductPackage.Volume * Cartons;
    /// <summary>
    /// 单品总重量, 单位: KG
    /// 公式: Weight => ProductPackage is null ? 0 : ProductPackage.Weight * Cartons;
    /// </summary>
    [DisplayName("重量"), Excel]
    public virtual decimal? Weight => ProductPackage is null ? 0 : ProductPackage.Weight * Cartons;

    /// <summary>
    /// 重量体积比, 用于计算装柜时的总重和总体积参考
    /// </summary>
    [DisplayName("重量体积比"), Excel]
    public virtual decimal? WeightVolumeRatio => Weight / Volume;
    /// <summary>
    /// 货值体积比, 用于计算装柜时的单品总价和总体积参考
    /// </summary>
    [DisplayName("货值体积比"), Excel]
    public virtual decimal? PriceVolumeRatio => Price / Volume;
    /// <summary>
    /// 重量体积比, 用于计算装柜时的单品总价和总重量参考
    /// </summary>
    [DisplayName("货值重量比"), Excel]
    public virtual decimal? PriceWeightRatio => Price / Weight;

    /// <summary>
    /// 货品
    /// </summary>
    public virtual ProductViewModel? Product { get; set; }
    /// <summary>
    /// 货品包装
    /// </summary>
    public virtual ProductPackageViewModel? ProductPackage { get; set; }
}

/// <summary>
/// 订单明细
/// </summary>
[DisplayName("订单明细")]
public abstract class OrderDetailViewModel<TKey> : ViewModel<TKey>, IViewModel<TKey>, IEntitySet<TKey> where TKey : IConvertible
{
    /// <summary>
    /// 订单编号
    /// </summary>
    [DisplayName("订单编号"), Required, MaxLength(36), Excel]
    public virtual TKey OrderId { get; set; } = default!;
    /// <summary>
    /// 货品编号
    /// </summary>
    [DisplayName("货品编号"), Required, MaxLength(36), Excel]
    public virtual TKey ProductId { get; set; } = default!;
    /// <summary>
    /// 货品包装编号
    /// </summary>
    [DisplayName("货品包装编号"), MaxLength(36), Excel]
    public virtual TKey? ProductPackageId { get; set; }
    /// <summary>
    /// 单价
    /// </summary>
    [DisplayName("单价"), Excel]
    public virtual decimal Price { get; set; }
    /// <summary>
    /// 数量
    /// </summary>
    [DisplayName("数量"), Excel]
    public virtual decimal Count { get; set; }
    /// <summary>
    /// 单品总箱数
    /// 公式: Cartons => ProductPackage is null ? 0 : (Count - 1) / ProductPackage.Count + 1;
    /// 使用单品总数量推导总箱数是准确值
    /// </summary>
    [DisplayName("总箱数"), Excel]
    public virtual decimal? Cartons { get; set; }
}